<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .send-data-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>短信任务</span>
    </div>
    <div class="line"></div>
    <send-data-form
      class="send-data-form"
      @on-success-valid="handleSubmit">
    </send-data-form>
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      :loading="loading"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import SendDataForm from '_c/send-data-form'
import TablePage from '_c/table-page'
export default {
  components: {
    SendDataForm,
    TablePage
  },
  data () {
    return {
      page: 1,
      title: '短信管理短信任务',
      rows: 20,
      playload: null,
      loading: true,
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '短信内容标题',
          key: 'name',
          minWidth: 200,
          align: 'center'
        },
        {
          title: '发送数量',
          key: 'cnt',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '发送群组',
          key: 'groupname',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '发送时间',
          key: 'ctime',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '发送状态',
          key: 'state',
          minWidth: 150,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.state === 0 ? '发送中' : params.row.state === 1 ? '已发送' : '-')
          }
        }
        // {
        //   title: '操作',
        //   key: 'cz',
        //   width: 196,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small',
        //           ghost: 'ghost'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         },
        //         on: {
        //           click: () => {
        //             this.handleClick(params.row.id, params.row)
        //           }
        //         }
        //       }, '编辑')
        //     ])
        //   }
        // }
      ]
    }
  },
  computed: {
    ...mapState({
      sendDataList: state => state.sendData.sendDataList,
      dataCount: state => state.sendData.sendDataDataCount,
      historyData: state => state.sendData.sendDataHistoryData,
      pageSize: state => state.sendData.sendDataPageSize
    })
  },
  methods: {
    ...mapActions([
      'getSendDataList',
      'changeSendDataPage',
      'changeSendDataPageSize'
    ]),
    handleSubmit (playload) {
      this.loading = true
      this.playload = playload
      // console.log(playload)
      this.getSendDataList({
        ...playload,
        rows: this.rows
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeSendDataPage(index)
      this.getSendDataList({
        page: index,
        rows: this.rows,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeSendDataPageSize(value)
      this.changePage(this.page)
      this.getSendDataList({
        rows: value,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getSendDataList({}).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
  }
}
</script>
